package entity;

import java.util.Comparator;

public class FTodo {
	public int id;
	public String taskname;
	public int priority;
	public int isFinish;
	public int dateCreate;
	public int timeCreate;
	public String reminder;
	public String place;
	public String people;
	public static final int PRIORITY_LOW = 1;
	public static final int PRIORITY_NORMAL = 2;
	public static final int PRIORITY_HIGHT = 3;

	public FTodo() {
		id = -1;
		taskname = "";
		priority = 1;
		isFinish = 0;
		dateCreate = 0;
		timeCreate = 0;
		reminder = "";
		place = "";
		people = "";
	}

	public enum SortParameter {
		ID_ASCENDING, 
		ID_DESCENDING, 
		FINISH_ASCENDING, 
		FINISH_DESCENDING, 
		PRIORITY_ASCENDING, 
		PRIORITY_DESCENDING, 
		TASKNAME_ASCENDING, 
		TASKNAME_DESCENDING,
	}

	public static Comparator<FTodo> getComparator(
			SortParameter... sortParameters) {
		return new FTodoComparator(sortParameters);
	}

	private static class FTodoComparator implements Comparator<FTodo> {
		private SortParameter[] parameters;

		private FTodoComparator(SortParameter[] parameters) {
			this.parameters = parameters;
		}

		public int compare(FTodo f1, FTodo f2) {
			int comparison;
			for (SortParameter parameter : parameters) {
				switch (parameter) {
				case ID_ASCENDING:
					comparison = f1.id - f2.id;
					if (comparison != 0) {
						return comparison;
					}
					break;
				case ID_DESCENDING:
					comparison = f2.id - f1.id;
					if (comparison != 0) {
						return comparison;
					}
					break;
				case FINISH_ASCENDING:
					comparison = f1.isFinish - f2.isFinish;
					if (comparison != 0) {
						return comparison;
					}
					break;
				case FINISH_DESCENDING:
					comparison = f2.isFinish - f1.isFinish;
					if (comparison != 0) {
						return comparison;
					}
					break;
				case PRIORITY_ASCENDING:
					comparison = f1.priority - f2.priority;
					if (comparison != 0) {
						return comparison;
					}
					break;
				case PRIORITY_DESCENDING:
					comparison = f2.priority - f1.priority;
					if (comparison != 0) {
						return comparison;
					}
					break;
				case TASKNAME_ASCENDING:
					comparison = f1.taskname.compareTo(f2.taskname);
					if (comparison != 0) {
						return comparison;
					}
					break;
				case TASKNAME_DESCENDING:
					comparison = f2.taskname.compareTo(f1.taskname);
					if (comparison != 0) {
						return comparison;
					}
					break;
				}
			}
			return 0;
		}
	}
}
